package com.adam.blog.controller;

import com.adam.blog.common.cache.Cache;
import com.adam.blog.service.TagService;
import com.adam.blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("tags")
public class TagsController {

    @Autowired
    private TagService tagService;

    /**
     * 最热标签获取
     * @return
     */
    @GetMapping("hot")
    @Cache(expire = 5 * 60 * 1000,name = "hot_tag")
    public Result hot(){
        int limit = 6;
        return tagService.hots(limit);
    }

    @GetMapping
    @Cache(expire = 5 * 60 * 1000,name = "list_tag")
    public Result tags(){
        return tagService.findAll();
    }

    @GetMapping("detail")
    @Cache(expire = 5 * 60 * 1000,name = "list_tag_detail")
    public Result tagsDetail(){
        return tagService.findAllDetail();
    }

    @GetMapping("detail/{id}")
    @Cache(expire = 5 * 60 * 1000,name = "list_tag_detail_byId")
    public Result tagsDetailById(@PathVariable("id") Long id){
        return tagService.findAllDetailById(id);
    }
}
